// https://umijs.org/config/
import { defineConfig } from 'umi';
import { join } from 'path';

import defaultSettings from './defaultSettings';
import proxy from './proxy';
import routes from './routes';
import plugins from './plugins';
import routesH5 from './routes.h5';

const { UMI_ENV, PLATFORM, KOAPORT } = process.env;
console.log(UMI_ENV, '----UMI_ENV---');
console.log(KOAPORT, '----KOAPORT---');

const base = {
  hash: false,
  ssr: {
    devServerRender: false,
  },
  antd: {},
  dva: {
    hmr: true,
    immer: { enableES5: true }, //如需兼容 IE11，需配置
  },
  dynamicImport: {
    loading: '@ant-design/pro-layout/es/PageLoading',
  },

  // bug  https://github.com/ant-design/ant-design/issues/33007
  lessLoader: {
    // golbalVars: {
    //   'root-entry-name': 'default'
    // }
    modifyVars: {
      'root-entry-name': 'default',
    },
  },
  // esbuild is father build tools
  // https://umijs.org/plugins/plugin-esbuild
  // esbuild: {},
  title: false,
  ignoreMomentLocale: true,
  proxy: proxy[UMI_ENV || 'dev'],
  // Fast Refresh 热更新
  fastRefresh: {},
  define: {
    UMI_ENV, // 注册到全局
    PLATFORM,
    KOAPORT,
  },
  nodeModulesTransform: { type: 'none' },
  // nodeModulesTransform: { type: 'all',  },
  // mfsu: false,
  // webpack5: {},
  // exportStatic: {},
};

const h5 = {
  ...base,
  hd: {
    // px2rem: {
    //   rootValue: 100,
    //   selectorDoubleRemList: [/.ant-/, /.adm-/],
    //   propBlackList: [
    //     'border-top-width',
    //     'border-left-width',
    //     'border-right-width',
    //     'border-bottom-width',
    //   ], // 这些属性不需要转换
    //   selectorBlackList: ['no_hd'], // 以包含no_hd的class不需要转换
    //   // exclude: /(node_module)/
    // },
  },
  antdMobile: {
    hd: true,
  },
  targets: {
    chrome: 49,
    ios: 10,
  },
  routes: routesH5,
};

const pc = {
  ...base,
  // title: 'CGJOY',
  hd: false,
  // Theme for antd: https://ant.design/docs/react/customize-theme-cn
  theme: {
    'primary-color': defaultSettings.primaryColor,
    'border-radius-base': '6px',
  },
  targets: {
    ie: 11,
  },
  // autoprefixer: {
  //   grid: "autoplace"
  // },
  routes,
};

const config = PLATFORM === 'h5' ? h5 : pc;
export default defineConfig(config as any);
